/**
 * Created by chengxiaolong on 2016/6/22.
 */
package com.invexer.service.baosteel {
import com.invexer.service.common.InvexerWebService;

import mx.rpc.events.FaultEvent;

import mx.rpc.events.InvokeEvent;

import mx.rpc.events.ResultEvent;
import mx.rpc.soap.LoadEvent;

import mx.rpc.soap.WebService;
import mx.utils.ObjectProxy;
import mx.utils.ObjectUtil;

import org.as3commons.logging.ILogger;

import org.as3commons.logging.LoggerFactory;

public class BaoSteelWebService implements IBaoSteelService {
    private static var logger : ILogger = LoggerFactory.getClassLogger(BaoSteelWebService);


    private var _invexerWebService:InvexerWebService;
    private var _productionMode:String;
    private var _config:Object;

    public function getApi(key:String):String{
        return _config.apis[key];
    }

    public function set productionMode(value:String):void {
        _productionMode = value;
    }

    public function set config(value:Object):void {
        _config = value;
        _invexerWebService = new InvexerWebService(_config.baseUrl[_productionMode]);
    }

    private function processData(data:Object):Object{
//        var jsonString:String = total as String;
//        if(!jsonString || jsonString.length==0) return null;
//
//        total = JSON.parse(jsonString);

        return data;
    }

    public function getHangZhouWeatherInfo(successCallback:Function, failCallback:Function):void {
        _invexerWebService.call(getApi("getWeatherbyCityName"), ["杭州"], successCallback, failCallback);
    }

    public function getCashFlowData(successCallback:Function, failCallback:Function):void {
    }

    
    public function getBalance(params:Object, successCallback:Function, failCallback:Function):void {
        _invexerWebService.call(getApi("getBalance"), params, function (data:ObjectProxy) {
            var result:Object = (data.balanceBase && data.balanceBase.length>0) ? data.balanceBase[0] : {};
            successCallback(result);
        }, failCallback);

    }
}
}
